package com.bishe.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bishe.pojo.BillType;
import com.bishe.pojo.UserBill;
import com.bishe.pojo.query.UserBillQuery;
import com.bishe.pojo.response.Result;
import com.bishe.service.BillTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("billType")
@Api(tags = "账单分类控制层")
public class BillTypeController {

    @Resource
    private BillTypeService billTypeService;

    @ApiOperation("新增或修改")
    @PostMapping("/addOrUpdate")
    public Result<?> addOrUpdate(@RequestBody BillType billType) {
        return Result.ok(billTypeService.saveOrUpdate(billType));
    }

    @ApiOperation("所有账单类型")
    @PostMapping("/getList")
    public Result<?> getList() {
        return Result.ok(billTypeService.list());
    }


    @GetMapping("/queryOne/{id}")
    @ApiOperation("根据id查询")
    public Result<?> queryOne(@PathVariable String id) {
        return Result.ok(billTypeService.getById(id));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("主键删除")
    public Result<?> delete(@PathVariable String id) {
        if (StrUtil.isEmpty(id)){
            return Result.error("id不能为空");
        }
        return Result.ok("操作成功",billTypeService.removeById(id));
    }
    
}
